<#include "../base.ftl"/>
<#macro css>

</#macro>

<#macro js>

</#macro>

<#macro title>
广大物流云平台
</#macro>
<#macro script>
$(function(){
    $("#gridTable").jqGrid({
        url:'${request.contextPath}/list!list.action',
        datatype: "json",
        mtype:"POST",
        height: 200,
        width: 1000,
        colNames:['Id','船舶代码','船舶名称','船东名称'],
        colModel:[
                          {name:'id',jsonmap:'ID',index:'ID',editable:true,hidden:true},
                          {name:'shippingCode',jsonmap:'SHIPPING_CODE',index:'SHIPPING_CODE',editable:true},
                          {name:'shippingName',jsonmap:'SHIPPING_NAME',index:'SHIPPING_NAME',editable:true},
                          {name:'ownerName',jsonmap:'OWNER_NAME',index:'OWNER_NAME',editable:true}, 
                          ],
        sortname : 'id',
        sortorder : 'desc',
        viewrecords : true,
        gridview : true,
        rownumbers : true,
        multiselect: true,
        rowNum : 20,
        rowList : [10,20,30],
        jsonReader : {
            page : "page.pageNo", //固定名称
            total : "page.totalPages", //固定名称
            records : "page.totalCount", //固定名称
            root : "page.result", //固定名称
            repeatitems : false, //固定
            id : 'ID'
        },
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        loadBeforeSend : function(xhr,settings){
            //设置需要访问的list标签
            settings.data=settings.data+ "&gridKey=/list#TsmAttention";
            return true;
        },
        pager : "#gridPager",
        caption : "关注船舶信息列表"
        }).navGrid('#gridPager', {
                edit : false,
                add : false, 
                del : false,
                
                search : false
        }, {  
                //edit
           //beforeSubmit:true,
           //reloadAfterSubmit : true, 
           //closeAfterEdit : true,  //修改完毕后关闭
           //afterComplete : opertaionPrompt, //更新结束后提示信息
           //onclickSubmit: fillCategoryId
        }, {
                //add
           //reloadAfterSubmit : true,
           //closeAfterAdd : true, //新增完毕后关闭
           //afterComplete : opertaionPrompt
           
       }).navButtonAdd('#gridPager',{
        
           caption:"添加关注",
           buttonicon:"ui-icon-add", 
           onClickButton: function(){
               var consoleDlg=$("#gridDialog");
               consoleDlg.dialog("option","title","添加船舶关注").dialog("open");
               
           }
           
       }).navButtonAdd('#gridPager',{
           caption:'取消关注',
           buttonicon:'ui-icon-del',
           onClickButton: function(){
              var selectId=$("#gridTable").jqGrid("getGridParam","selrow");
              var id=jQuery("#gridTable").jqGrid('getRowData',selectId).id;
              //alert(id);
              if(selectId==null){
                  alert("请选择船舶");
              }else{
                  $.ajax({
                     url: '{request.contextPath}/operator.action',
                     type:'post',
                     data:{"beanName":"tsm.TsmAttention","oper":"del","id":id},
                     dataType : 'json',
                     success:function(result){
                         alert(result.message);
                         jQuery("#gridTable").trigger('reloadGrid');

                     }
                  });
              }  
               
               
           }
       });
       

    $("#gridDialog").dialog({
    
        autoOpen: false,
        model:true,  //设置对话框为模态对话框
        resizable: true,
        width: 550,
        height: 300,
        open : function(){
            //var selectedId=$("#gridTable").jqGrid("getGridParm","selrow");
            $("#gridAttentionTable").jqGrid({
                url: "${request.contextPath}/list!list.action?userId='el:currUser.userId'",
              
                datatype: "json",
                mtype:"POST",
                colNames:['ID','船舶代码','船舶名称','船东名称','shippingId'],
                colModel:[
                          {name:'id',jsonmap:'ID',index:'ID',editable:false,hidden:true},
                          {name:'shippingCode',jsonmap:'SHIPPING_CODE',index:'SHIPPING_ID',editable:true},
                          {name:'shippingName',jsonmap:'SHIPPING_NAME',index:'SHIPPING_NAME',editable:true},
                          {name:'ownerName',jsonmap:'OWNER_NAME',index:'OWNER_NAME',editable:true}, 
                          {name:'shippingId',jsonmap:'SHIPPING_ID',index:'SHIPPING_ID',editable:true}, 
                          ],
                sortname : 'SHIPPING_NAME',
                sortorder : 'desc',
                viewrecords : true,
                gridview : true,
                rownumbers : true,
                multiselect: true,
                rowNum : 20,
                rowList : [10,20,30],
                jsonReader : {
                 
                    page : "page.pageNo", //固定名称
                    total : "page.totalPages", //固定名称
                    records : "page.totalCount", //固定名称
                    root : "page.result", //固定名称
                    repeatitems : false, //固定
                    id : 'ID'
                },
                prmNames : {
                    rows : "page.pageSize",
                    page : "page.pageNo",
                    sort : "page.orderBy",
                    order : "page.order"
                },
                loadBeforeSend:function(xhr,settings){
                //设置需要访问的list标签
                  
                  settings.data=settings.data+ "&gridKey=/list#TsmAttentionTable";
                  return true;
                 },
                 
                 pager : "#gridAttentionPager" 
            });
       
            jQuery("#gridAttentionTable").trigger('reloadGrid');
            
          },
          buttons: {//为对话框添加按钮
                    "关注船舶":addUser,
                    "取消":function() {$("#gridDialog").dialog("close")}
                  }
         
         
    });
   });
var addUser=function(){
    var selectedId = $("#gridAttentionTable").jqGrid(
            "getGridParam", "selrow");
            //alert(selectedId);
    var shippingId=jQuery("#gridAttentionTable").jqGrid('getRowData',selectedId).shippingId;
    //alert(shippingId);
    var postData=$(
       "#gridAttentionTable").jqGrid("getGridParam","postData");
    
    if (selectedId==null){
        alert("请选择");
    }else{
        $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{'shippingId':shippingId,"beanName":"tsm.TsmAttention","oper":"add","userId":"el:currUser.userId"},
            dataType : 'json',
            success:function(result){
                alert(result.message);
                jQuery("#gridTable").trigger('reloadGrid');
                jQuery("#gridAttentionTable").trigger('reloadGrid');
                $("#gridDialog").dialog("close")
                           
            }
        });
        
    }
}
  
</#macro>

<#macro main>
  <div id="detaildiv" style="float:left;width:200px">
           <table id="gridTable"></table>
           <div id="gridPager"></div>
  </div>
 <div id="gridDialog">  
                <form id="consoleForm">  
                    <input type="hidden" id="selectId" />  
                    <table id="gridAttentionTable" class="formTable">  
                    </table>
                    <div id="gridAttentionPager"></div>
                </form>  
            </div>  
</#macro>
